package day8.problem2;

//数组中的最长连续子序列
//https://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf?tpId=196&tqId=37143&ru=/exam/oj

import java.util.*;


public class Solution {
    public int MLS (int[] arr) {
        Set<Integer> set = new HashSet<>();
        for(int x : arr) {
            set.add(x);
        }
        int ret = 0;
        for(int x : set) {
            if(!set.contains(x-1)) {
                int count = 1;
                while(set.contains(x + 1)) {
                    x = x + 1;
                    count++;
                }
                ret = Math.max(ret, count);
            }
        }
        return ret;
    }
}